package com.suxin.reflection;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
import java.util.stream.Stream;

/**
 * @author Tang
 * @classname ReflectionClass
 * @description [  ]
 * @date 2021/10/20 16:57
 */
@Slf4j
public class ReflectionClass {

    /**
     * 反射获取父类的泛型信息
     */
    @Test
    public void test01() {
        AA aa = new AA();
        Class<? extends AA> aClass = aa.getClass();
        ParameterizedType parameterizedType = (ParameterizedType) aClass.getGenericSuperclass();
        Stream.of(parameterizedType.getActualTypeArguments()).forEach(item -> {
            System.out.println("泛型信息:--->" + item.getTypeName());
        });
    }

}

class AA extends HashMap<String, String> {
}